<!--
 * @Author: your name
 * @Date: 2021-09-06 16:53:09
 * @LastEditTime: 2021-09-10 17:06:31
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \EJ-WEBUI\src\views\Audit hall\real\index.vue
-->
<template>
  <div class="production">
    <div class="btns">
      <!-- 检索框 -->
      <el-form :inline="true" :model="params" size="small">
        <el-button
        :plain="true"
          type="danger"
          size="small"
          style="margin-right: 10px"
          @click="delectComments"
          >批量删除</el-button
        >
        <el-form-item>
          <el-input v-model="params.name" placeholder="请输入关键字"></el-input>
        </el-form-item>
        <!-- 查询按钮 -->
        <el-button
          type="primary"
          size="small"
          style="margin-right: 10px"
          @click="pageQueryComments"
          icon="el-icon-search"
          >查询</el-button
        >
      </el-form>
    </div>
    <div class="content">
      <!-- 表格 -->
      <el-table
        :data="resData.list"
        style="width: 100%"
        size="small"
        ref="multipleTable"
        @selection-change="handleSelectionChange"
      >
        <el-table-column type="selection" width="55"></el-table-column>
        <el-table-column type="index" label="序号"></el-table-column>
        <el-table-column label="评论内容" prop="comment"></el-table-column>
        <el-table-column label="评论人编号" prop="userId"></el-table-column>
        <el-table-column label="资讯编号" prop="articleId"></el-table-column>
        <el-table-column
          v-if="resData.list && resData.list != ''"
          label="评论时间"
          prop=""
        >
          {{ resData.list[0].commentTime | fmtDate }}
        </el-table-column>
        <el-table-column label="状态" prop="status">
          <template v-slot="scope">
            <el-tag
              v-if="scope.row.status == '通过'"
              size="mini"
              type="success"
              >{{ scope.row.status }}</el-tag
            >
            <el-tag
              v-else-if="scope.row.status == '不通过'"
              size="mini"
              type="warning"
            >
              {{ scope.row.status }}</el-tag
            >
            <el-tag v-else size="mini" type="danger">
              {{ scope.row.status }}</el-tag
            >
          </template>
        </el-table-column>
        <!-- 操作列 -->
        <el-table-column label="操作">
          <template v-slot="scope">
            <div v-if="scope.row.status == '未审核'">
              <el-button
                type="text"
                @click="offlineHandler(scope.row.id, $event)"
                style="color: #84bf96"
                >通过</el-button
              >
              <el-button
                type="text"
                style="color: #f391a9"
                @click="offlineHandler(scope.row.id, $event)"
                >不通过</el-button
              >
            </div>
            <div v-else>
              <el-button
                type="text"
                @click="offlineHandler(scope.row.id, $event)"
                style="color: #ac6767"
                >删除</el-button
              >
            </div>
          </template>
        </el-table-column>
      </el-table>
      <!-- 分页 -->
      <el-pagination
        background
        align="center"
        layout="prev, pager, next, sizes"
        :total="resData.total"
        :page-size="params.pageSize"
        :current-page="params.page"
        @current-change="pageChangeHandler"
        :page-sizes="[5, 10, 15]"
        @size-change="pageSizeChangeHandler"
      >
      </el-pagination>
    </div>
  </div>
</template>
<script>
import requset from "@/utils/request";
import _ from "lodash";
export default {
  data() {
    return {
      params: {
        page: 1,
        pageSize: 5,
      },
      ids: [],
      time: null,
      resData: {},
      categories: [],
      formLabelWidth: "80px",
    };
  },
  methods: {
    // 选中行的绑定事件

    // 批量删除功能
    delectComments() {
      if(this.multipleSelection){
        this.multipleSelection.forEach((value, index, array) => {
        this.ids.push(array[index].id);
        this.$confirm("是否确认该操作?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(() => {
          requset
            .get("/Comment/checkNoPass", { params: { ids:this.ids } })
            .then((res) => {
              this.pageQueryComments(); // 重载数据
              this.$message.success(res.message); // 提示信息
            });
      }).catch(()=>{});
      });
      } else{
        this.$message("请选择要删除的数据");
      
      }
    },
    // 监听选中项的改变
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    // 分页查询产品表格
    async pageQueryComments() {
      // 过滤数据将空字符串删除
      for (let key in this.params) {
        if (this.params[key] == "") {
          delete this.params[key];
        }
      }
      // 判断日期时间选择器是否有数据，有则将数据放入params中
      if (this.time) {
        this.params.beginTime = this.time[0];
        this.params.endTime = this.time[1];
      } else {
        delete this.params.beginTime;
        delete this.params.endTime;
      }
      let res = await requset.get("/comment/pageQuery", {
        params: this.params,
      });
      this.resData = res.data;
      // console.log(this.params);
      //  console.log(this.resData.list);
    },
    // page改变事件
    pageChangeHandler(page) {
      this.params.page = page;
      this.pageQueryComments();
    },
    // pageSize改变事件
    pageSizeChangeHandler(pageSize) {
      this.params.pageSize = pageSize;
      this.pageQueryComments();
    },
    // 通过、不同个执行处理程序
    offlineHandler(id, e) {
      this.$confirm("是否确认该操作?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(() => {
        if (e.target.innerText == "不通过") {
          requset
            .get("/Comment/checkNoPass", { params: { id, status: "不通过" } })
            .then((res) => {
              this.pageQueryComments(); // 重载数据
              this.$message.success(res.message); // 提示信息
            });
        } else if (e.target.innerText == "通过") {
          requset
            .get("/Comment/checkPass", { params: { id, status: "通过" } })
            .then((res) => {
              this.pageQueryComments(); // 重载数据
              this.$message.success(res.message); // 提示信息
            });
        } else {
          requset.get("/comment/deleteById", { params: { id } }).then((res) => {
            this.pageQueryComments(); // 重载数据
            this.$message.success(res.message); // 提示信息
          });
        }
      }).catch(()=>{});
    }
  },
  created() {
    this.pageQueryComments(); // 分页查询产品
  },
};
</script>
<style>
.el-pagination {
  margin: 30px;
}
.avatar-uploader .el-upload {
  border: 1px dashed #d9d9d9;
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}
.avatar-uploader .el-upload:hover {
  border-color: #409eff;
}
.avatar-uploader-icon {
  font-size: 28px;
  color: #8c939d;
  width: 178px;
  height: 178px;
  line-height: 178px;
  text-align: center;
}
.avatar {
  width: 178px;
  height: 178px;
  display: block;
}
</style>
